<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>js元素对象</title>
	<style>
	#kuang{
		width: 300px;
		height: 300px;
		background: yellow url() 0 0 no-repeat;
	}
	</style>

	<script type="text/javascript">
		window.onload=function(){
			var star=document.getElementById("star");
			var kuang=document.getElementById("kuang");
				var width=200;
				var height=200;

			var c=1;
			function run(){
				if (c==1) {
					width +=1;
					height +=1;

					if (width>500) {
						c=0;
					}
				}else{
					width -=1;
					height -=1;

					if (width<200) {
						c=1;
					};
				}

				kuang.style.width=width+"px";
				kuang.style.height=height+"px";
			}

			var go=1
			star.onclick=function(){
					if(go==1){
					time = setInterval(run, 10);
					star.value ="跑起来";
					go =0;
					}else{
						clearInterval(time);
						star.value ="跑起来";
						go =1;
						}
			}

		}

	</script>
</head>
<body>
	<input type="button" value="跑起来" id="star">
	<div id="kuang"><img src="" alt=""></div>
</body>
</html>